<?php
// Error Reporting
error_reporting(E_ALL);

// HTTP
define('HTTP_INSTALL', 'http://' . $_SERVER['HTTP_HOST'] . rtrim(dirname($_SERVER['SCRIPT_NAME']), '/.\\') . '/');
define('HTTPS_INSTALL', 'https://' . $_SERVER['HTTP_HOST'] . rtrim(dirname($_SERVER['SCRIPT_NAME']), '/.\\') . '/');
define('HTTP_SERVER', 'http://' . $_SERVER['HTTP_HOST'] . rtrim(rtrim(dirname($_SERVER['SCRIPT_NAME']), 'install'), '/.\\'). '/');
define('HTTPS_SERVER', 'http://' . $_SERVER['HTTP_HOST'] . rtrim(rtrim(dirname($_SERVER['SCRIPT_NAME']), 'install'), '/.\\'). '/');

define('DIR_SYSTEM', str_replace('\'', '/', realpath(dirname(__FILE__) . '/../')) . '/system/');

// Startup
require_once(DIR_SYSTEM . 'startup.php');
require_once(DIR_SYSTEM . 'include.php');


// Front Controller
$controller = new Front(DIR_SYSTEM);

// Installer auto configuration injection
$dir_app  = str_replace('\'', '/', realpath(dirname(__FILE__))) . '/';
$dir_root = str_replace('\'', '/', realpath($dir_app . '../')) . '/';

$controller->get('load')->set_paths(array(
	'dir_cache'     => DIR_SYSTEM.'/cache',
    'dir_root'      => $dir_root,
    'dir_config'    => DIR_SYSTEM . 'config/'
));

$config = $controller->get('load')->config('install');

$config->set_section('app')
    ->set_all(array(
        'id'        => 'install',
        'classname' => 'app_install',
        'filename'  => 'install.php',
        'bootstrap' => 'bootstrap.php'
    ));

$config->set_section('paths')
    ->set_all(array(
    	'dir_app'       => $dir_app,
        'dir_language'  => $dir_app . 'language/',
        'dir_template'  => $dir_app . 'view/',
    ));

$app = $controller->bootstrap($config);

// Dispatch
echo $controller->dispatch($app);
?>
